<template>

    <span>{{name}}</span>
    
</template>

<script>

    import persistentUtil from '@/common/persistentUtil.js'
    import event from '../../plugins/event'

    export default {

        props:[
            "dictIdent",
            "dictKey"
        ],
        name: "SystemDictDisplay"
        ,
        data(){
          return {
              name:''
          };
        },
        mounted(){

            this.loadDictItem();

        },
        methods:{

            loadDictItem(){
                if(this.dictIdent && this.dictKey){

                    persistentUtil.getDictItem(this.dictIdent,this.dictKey,s=>{

                        if(s){

                            this.name = s.itemName;
                        }else{

                            this.loadRemoteDict();
                            // this.loadRemote();
                        }

                    },e=>{

                        // this.loadRemote();
                        this.loadRemoteDict();
                    });
                }
            },


            loadRemoteDict(){
                event.$emit("loadRemoteDict",this.dictIdent)

                event.$on("loadRemoteDictFinish",ident=>{

                    if(ident == this.dictIdent){

                        persistentUtil.getDictItem(this.dictIdent,this.dictKey,s=>{

                            if(s){

                                this.name = s.itemName;
                            }else{

                                this.name = "字典加载失败";
                                // this.loadRemote();
                            }

                        })

                    }
                })
            }

        },
        destroyed(){

            event.$off("loadRemoteDict")
            event.$off("loadRemoteDict")
        },

        watch:{
            dictKey(){
              this.loadDictItem()
            }
        }
    }
</script>

<style scoped>

</style>